package com.google.code.avajhelpdesk.entities;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;

import org.hibernate.annotations.CollectionOfElements;

@Entity(name = "user")
public class User extends BasicEntity {

	public static final String ROLE_USER = "user";
	public static final String ROLE_ADMIN = "admin";
	
	public static final int MIN_USERNAME_LENGTH = 3;
	public static final int MAX_USERNAME_LENGTH = 32;
	public static final int MAX_FIRSTNAME_LENGTH = 32;	
	public static final int MAX_LASTNAME_LENGTH = 32;
	public static final int MIN_PASSWORD_LENGTH = 6;
	public static final int MAX_PASSWORD_LENGTH = 32;
	
	/**
	 * Autogenerated id
	 */
	private static final long serialVersionUID = -3239225920803789311L;

	@Column(nullable = false, unique = true, length = MAX_USERNAME_LENGTH)
	private String username = "";
	
	@Column(length = MAX_FIRSTNAME_LENGTH, name = "first_name")
	private String firstName = "";

	@Column(length = MAX_LASTNAME_LENGTH, name = "last_name")
	private String lastName = "";
	
	@Column(length = MAX_PASSWORD_LENGTH)
	private String password = "";
	
	@OneToMany(mappedBy="owner")
	private Set<Issue> ownedIssues = new HashSet<Issue>();
	
	@Column(length=1024)
	private String contactInfo = "";
	
	@CollectionOfElements
	@JoinTable(name = "user_roles", joinColumns = {@JoinColumn(name = "user_id")})
	private Set<String> roles = new HashSet<String>();

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public Set<Issue> getOwnedIssues() {
		return ownedIssues;
	}
	
	public void setOwnedIssues(Set<Issue> ownedIssues) {
		this.ownedIssues = ownedIssues;
	}

	public String getContactInfo() {
		return contactInfo;
	}

	public void setContactInfo(String contactInfo) {
		this.contactInfo = contactInfo;
	}

	public Set<String> getRoles() {
		return roles;
	}

	public void setRoles(Set<String> roles) {
		this.roles = roles;
	}
}